package num703;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.PriorityQueue;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/10 0:04
 * @Desc :
 */
class KthLargest {
  PriorityQueue<Integer> priorityQueue;
  int k ;
  public KthLargest(int k, int[] nums) {
    this.k = k;
    priorityQueue = new PriorityQueue<>(k);
    for (int num : nums) {
      add(num);
    }
  }

  public int add(int val) {
    priorityQueue.add(val);
    if (priorityQueue.size() > k) {
      priorityQueue.poll();
    }
    return priorityQueue.peek();
  }

  public static void main(String[] args) {

  }
}
